﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Filters;



namespace WLW4Ceng.APIHost.AOP_面向切面_
{
    /// <summary>
    /// 自定义行为过滤器
    /// </summary>
    public class MyActionFilter : IAsyncActionFilter
    {
        /// <summary>
        /// 实现接口方法
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            //需求 :记录每一个api请求 所花费的时间
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            next();

            stopwatch.Stop();

            string  api = context.HttpContext.Request.Path;

            //把用户放的api地址和耗时 记录到Nlog

            return Task.CompletedTask;
        }
    }
}
